import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import nba2kmodtool.filedesc.N2kTextureFile;
import nba2kmodtool.filedesc.v2010.IffFile;

public class MainPicFrameTest10 extends JFrame {

	public static void main(String[] args) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					//IffFile iff = new IffFile(new File("D:/My Documents/ababall.iff"));
					//IffFile iff = new IffFile(new File("D:/My Documents/nbaball.iff"));
					//IffFile iff = new IffFile(new File("D:/My Documents/s001.iff"));
					//IffFile iff = new IffFile(new File("D:/png177.iff"));
					//IffFile iff = new IffFile(new File("D:/png177_0.iff"));
					//IffFile iff = new IffFile(new File("C:/png1013_0.iff")); 
					IffFile iff = new IffFile(new File("C://ua000.iff"));
					MainPicFrameTest10 objLoad = new MainPicFrameTest10(iff);
					objLoad.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(-1);
				}
			}
		});
	}

	public MainPicFrameTest10(IffFile iff) {
		this.setTitle("N2K_x Iff Pic Frame Test");
		this.iff = iff;
		// Initialize the GUI components
		initComponents();
	}

	public void load() {
		try {
			N2kTextureFile texture = iff.readTextureFile(16);
			image = iff.readN2KTexture(texture);
			ishow.setIcon(new ImageIcon(image));
			ishow.updateUI();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void initComponents() {
		drawingPanel = new javax.swing.JPanel();
		JPanel tool = new JPanel();
		tool.setLayout(new BorderLayout());
		JButton button = new JButton("Load");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				load();
			}
		});
		tool.add(button, BorderLayout.NORTH);
		add(tool, BorderLayout.NORTH);

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("ObjLoad");
		drawingPanel.setLayout(new java.awt.BorderLayout());

		image = new BufferedImage(400, 400, Image.SCALE_SMOOTH);
		ishow = new JLabel(new ImageIcon(image));
		N2kTextureFile texture;
		try {
			//5, 16
			//11
			texture = iff.readTextureFile(11);
			image = iff.readN2KTexture(texture);
			ishow.setIcon(new ImageIcon(image));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		drawingPanel.add(ishow, BorderLayout.CENTER);
		drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700));
		getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER);

		pack();
	}

	private JPanel drawingPanel;
	private IffFile iff;
	private Image image;
	private JLabel ishow;
}
